<template>
	<div>
    <div class="container">
		<div class="handle-box">
			<label class="label" >关键词：</label>
			<el-input class="handle-input" v-model="keyword"/>
				<el-button color="#1C84C6" class="handle-btn" @click="handleSearch">查询</el-button>
				<el-row class="top-btn">
     			<!-- <el-button-group class="ml-4"> -->
                    <el-button color="#23c6c8"  style="color: #fff;" @click="open">添加</el-button> 
                    <el-button color="#ED5565"  style="color: #fff;" @click="handleAllDelete">删除</el-button>                         
       		 <!-- </el-button-group> -->
			</el-row>
			</div>
			<el-table ref="multipleTableRef" 
				:header-cell-style="{color:'#2A62BC'}"
			 	:data="tableData"   
			 	style="width: 100%;" 
                size="small"
                border
				@selection-change="handleSelectionChange">
                <el-table-column   type="selection" width="35" />
				<el-table-column  prop="t_id" label="序号" align="center" ></el-table-column>
				<el-table-column prop="name" label="模板名称" align="center"></el-table-column>
				<el-table-column label="是否启用" align="center">
                    <template #default="scope">
                        <el-switch
                                v-model="scope.row.status"
                                :active-value="'启用'"
                                :inactive-value="'不启用'"
                                active-color="#64bd63"
                                inactive-color="#c0c0c0"
                                
                                @change="changeSwitch(scope.row.status)"/>
					</template>
                </el-table-column>
				<el-table-column label="操作" width="220" align="center" >
					<template #default="scope">
							<el-row class="right-btn">
                            <el-tooltip content="查看考评选项" placement="bottom" effect="light">
						        <el-button   @click="detail(scope.row)" >
                                    <i class="iconfont icon-info-circle-fill1 white " style="color:#23c6c8 ;"></i>
                                </el-button>
                            </el-tooltip>
                            <el-tooltip content="修改" placement="bottom" effect="light">
						        <el-button  :icon="Edit" @click="open(scope.$index,scope.row)" ></el-button>
                            </el-tooltip>
                            <el-tooltip content="删除" placement="bottom" effect="light">
				            <el-button   style="color:#e35148;" :icon="Delete"  @click="handleDelete(scope.$index)"></el-button>
                        </el-tooltip>
						</el-row>
					</template>
				</el-table-column>
			</el-table>
			<!-- 分页 -->
			<div class="pagination">
				<el-pagination
				:current-page="query.pageIndex"
					:page-size="query.pageSize"
					:page-sizes="[5, 10, 15, 20]"
					size="small"
					layout="total, sizes, prev, pager, next, jumper"
					:total="pageTotal"
					@size-change="handleSizeChange"
					@current-change="handlePageChange"/>
			</div>
	</div>

		<!-- 修改/添加弹出框 -->
		<el-dialog :title="titleEdit" v-model="editVisible" width="25%" >
			<el-form label-width="70px">
				<el-form-item label="模板名称" disabled >
					<el-input v-model="form.name"  placeholder="请输入考评内容"></el-input>
				</el-form-item>
				<el-form-item label="考评选项" disabled >
					<el-select v-model="form.option" placeholder="请选择考评选项">
                      <el-option :label="1" :value="1"></el-option>
                    </el-select>
				</el-form-item>
                <el-form-item label="是否启用" v-if="titleEdit=='添加'">
					<el-switch
                                v-model="form.status"
                                :active-value="0"
                                :inactive-value="1"
                                active-color="#64bd63"
                                inactive-color="#c0c0c0"/>	
				</el-form-item>          
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button color="#C2C2C2" style="color:#fff" @click="editVisible = false">关闭</el-button>
					<el-button color="#0ab394" @click="saveEdit">确 定</el-button>
				</span>
			</template>
		</el-dialog>
		<!--考评内容弹出框 -->
		<el-dialog title="考评内容" v-model="starVisible" width="25%" >
           <div class="dialog-div" style="border-top:  1px solid #c2c2c2;">
            <label style="width: 41.666666667%;">教师是否按照大纲案例授课，并且是否由缺课？</label>
            <el-tooltip content="clear" placement="bottom" effect="light">
            <el-button circle type="info" :icon="Minus" @click="clearStar" style="width: 20px;height: 20px;"></el-button>
             </el-tooltip>
            <el-rate
                v-model="starData.evaluate"
                :texts="['极差', '差', '一般', '良好', '优秀']"
                show-text
                clearable
                size="large" 
            />
           </div>
           <div class="dialog-div">
            <label style="width: 41.666666667%;">教师是否按照大纲案例授课，并且是否由缺课？</label>
            <el-tooltip content="clear" placement="bottom" effect="light">
            <el-button circle type="info" :icon="Minus" @click="clearStar" style="width: 20px;height: 20px;"></el-button>
             </el-tooltip>
            <el-rate
                v-model="starData.evaluate"
                :texts="['极差', '差', '一般', '良好', '优秀']"
                show-text
                clearable
                size="large" 
            />
           </div>
           <div class="dialog-div">
            <label style="width: 41.666666667%;">教师是否按照大纲案例授课，并且是否由缺课？</label>
            <el-tooltip content="clear" placement="bottom" effect="light">
            <el-button circle type="info" :icon="Minus" @click="clearStar" style="width: 20px;height: 20px;"></el-button>
             </el-tooltip>
            <el-rate
                v-model="starData.evaluate"
                :texts="['极差', '差', '一般', '良好', '优秀']"
                show-text
                clearable
                size="large" 
            />
           </div>
           <div class="dialog-div">
            <label style="width: 41.666666667%;">教师是否按照大纲案例授课，并且是否由缺课？</label>
            <el-tooltip content="clear" placement="bottom" effect="light">
            <el-button circle type="info" :icon="Minus" @click="clearStar" style="width: 20px;height: 20px;"></el-button>
             </el-tooltip>
            <el-rate
                v-model="starData.evaluate"
                :texts="['极差', '差', '一般', '良好', '优秀']"
                show-text
                clearable
                size="large" 
            />
           </div>
           <div class="dialog-div">
            <label style="width: 41.666666667%;">教师是否按照大纲案例授课，并且是否由缺课？</label>
            <el-tooltip content="clear" placement="bottom" effect="light">
            <el-button circle type="info" :icon="Minus" @click="clearStar" style="width: 20px;height: 20px;"></el-button>
             </el-tooltip>
            <el-rate
                v-model="starData.evaluate"
                :texts="['极差', '差', '一般', '良好', '优秀']"
                show-text
                clearable
                size="large" 
            />
           </div>
           
		
		</el-dialog>

		<!-- </div> -->
	</div>
</template>

<script setup >
import { ref, reactive } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import { Delete, Edit, Search, Plus ,Minus} from '@element-plus/icons-vue';
import { getPollTemplate} from '../../api/evaluation'

const keyword = ref('')

//分页字体
const small = ref(true)
// const size = ref<'default' | 'large' | 'small'>('default')

//分页数据
const query = reactive({
	pageIndex: 1,
	pageSize: 5,
});
//

//表格数据
const tableData = ref();
//总页数
const pageTotal = ref(0);
const multipleTableRef = ref()
const state = reactive({
	multipleSelection:[]
})

// 获取表格数据  分页是数据截取  后台结合一起后  直接返回分页的后的数据
const getData = () => {
    getPollTemplate({pageCurrent:query.pageIndex,pageSize:query.pageSize}).then(res=>{
        console.log(res,"---res---")
        // tableData.value = res.data.
		let start  = (query.pageIndex-1)*query.pageSize;//开始位置
        let end =query.pageIndex*query.pageSize  ;//结束位置 数组的截取的时候 [start,end) suo所以不用-1
        tableData.value = res.data.slice(start,end);
        // tableData.value = res.data;
        pageTotal.value = res.data.length
    })
	
};
getData();
//多选框权限
const handleSelectionChange = (val) => {
  state.multipleSelection = val
}
// 分页导航
const handleSizeChange = (val) => {
  // console.log(`${val} items per page`)
  query.pageSize = val;
  getData()
}
const handlePageChange = (val) => {
	query.pageIndex = val;
	console.log(val,"==")
	console.log(query.pageSize)
	getData()
};


//是够启用调用后台接口
const  changeSwitch=(status)=>{
    //调用后台修改接口
    console.log(status,'>>>status');
}

// 删除单个操作
const handleDelete = (index) => {
	// 二次确认删除
	ElMessageBox.confirm('确定要删除吗？', '提示', {
		type: 'warning'
	})
	.then(() => {
		ElMessage.success('删除成功');
		//to 传递id 到后台 
		tableData.value.splice(index, 1);
		// 删除成功后
		// getData()
	})
	.catch(() => {});
};
//删除多个数据  to......
const handleAllDelete =()=>{
	// console.log('删除多个')
	console.log(state.multipleSelection,'===拿到所有选择的数据====')
	if (state.multipleSelection.length==0) {
		ElMessage.error('请选择项')
		return
  	}
	// console.log(state.multipleSelection.map(item=>item.id))
	//axios删除的操作
	// deleteAllAdmin({ids:state.multipleSelection.map(item=>item.id)})

	
}


// 查询操作  to... 需要自己实现与后台交互
const handleSearch = () => {
	query.pageIndex = 1;
	getData();
};

// 表格编辑时弹窗和保存
const editVisible = ref(false);
let form = reactive({
    id:'',
	name: '',
    option:'',
    status:''
    
});

// 
let titleEdit = ref('修改')
let isDisable = ref(true)
const open  = (index,row)=>{//index是时间源对象
	if(row){
		titleEdit.value = "修改"
		handleEdit(index,row)
	}else{
		//把第一个输出改为可编辑
		isDisable.value=false
		//清空表单中的数据
		titleEdit.value = "添加";
		form.name=''
        form.option=''
		editVisible.value = true	
	}
	console.log('-------测试传值-------')
	// console.log(index,row,index.target.innerText)
	// console.log(index,row)
	// console.log('================')

}
let idx = -1;
const handleEdit = (index,row) => {
	idx = index;
    form.id = row.id;
	form.name = row.content
	editVisible.value = true;
};
//保存添加或者修改的数据 ---需要重新实现
const saveEdit = () => {
	editVisible.value = false;
	ElMessage.success(`修改第 ${idx + 1} 行成功`);
	tableData.value[idx].name = form.name;
};

//考评内容弹框
const  starVisible = ref(false)
const  starData = reactive({
    evaluate:'1',
})
const  detail=(row)=>{
    starVisible.value= true
}
const clearStar=()=>{
    starData.evaluate =''
}
</script >
<style lang="less" scoped>
.handle-box {
	margin-bottom: 20px;   
	.handle-btn{
		margin-left: 10px;
	}
}

.dialog-div{
    font-size: 13px;
    font-weight: 600; 
    padding: 7px 0px 15px 7px;
    margin: 0px 15px;
    border-bottom:  1px solid #c2c2c2;

}

.el-select {
	width: 200px;
	// margin-right: 10px;  
}
.el-rate{
   --el-rate-text-color:#ed5565

}
.handle-input {
	width: 200px;
    margin-right: 10px;
}
.label{
   display: inline-block;
   max-width:100%;
   margin: 5px;
   font-weight: 700; 
}
.table {
	width: 100%;
	font-size: 14px;
}



.top-btn{
	float: right;
	.el-button{
		margin-left: 5px;
	}
}
.right-btn{
 	justify-content:center;
	.el-button{
		height: 22px;
		// width: 60px;
		margin-right: 2px;
		padding: 1px 5px;
	}
}


</style>